package com.example.personalinfo.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.personalinfo.MyApplication;
import com.example.personalinfo.db.UserDao;
import com.example.personalinfo.db.UserDatabase;
import com.example.personalinfo.model.User;
import com.example.personalinfo.respository.UserRepository;

public class UserViewModel extends AndroidViewModel {

    private final LiveData<User> user;

    private final UserRepository userRepository;

    private final String userName = "Grimness";

    public UserViewModel(@NonNull Application application) {
        super(application);
        UserDatabase userDatabase = MyApplication.getUserDatabase();
        UserDao userDao = userDatabase.userDao();
        userRepository = new UserRepository(userDao, MyApplication.getApi());
        user = userRepository.getUser(userName);
    }

    public LiveData<User> getUser() {
        return user;
    }

    public void refresh() {
        userRepository.refresh(userName);
    }
}
